package com.CmJava.crowd.entity;



public class ResultEntity<T> {
    private boolean resultFlag;
    private String message;
    private T data;
    private static final boolean success = true;
    private static final boolean failure =false;
    private static final String successMsg = "success";
    private static final String failureMsg="failure";

    public ResultEntity() {
    }

    public ResultEntity(boolean resultFlag, String message, T data) {
        this.resultFlag = resultFlag;
        this.message = message;
        this.data = data;
    }

    public boolean getResultFlag() {
        return resultFlag;
    }

    public void setResultFlag(boolean resultFlag) {
        this.resultFlag = resultFlag;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
    //需要返回数据的成功请求
    public static <E> ResultEntity<E> successWithData(E e){
        return new ResultEntity<E>(success,successMsg,e);
    }
    //不需要返回数据的成功请求
    public static <E> ResultEntity<E> successWithoutData(){
        return new ResultEntity<E>(success,successMsg,null);
    }
    //失败请求，需要具体的失败原因
    public static <E> ResultEntity<E> failWithMessage(String message){
        return new ResultEntity<E>(failure,message,null);
    }
    //不需要返回数据的失败请求
    public static <E> ResultEntity<E> failWithoutMessage(){
        return new ResultEntity<E>(failure,failureMsg,null);
    }

    @Override
    public String toString() {
        return "{" +
                "resultFlag:" + resultFlag +
                ", message:'" + message + '\'' +
                ", data:" + data +
                '}';
    }
}
